package com.jiashn.minio.controller;

import com.jiashn.minio.utils.JsonResult;
import com.jiashn.minio.utils.MinioBucketEnum;
import com.jiashn.minio.service.OpuSysFilesService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: jiangjs
 * @description:
 * @date: 2023/10/23 11:27
 **/
@RestController
@RequestMapping("/sysFile")
public class OpuSysFilesController {

    @Resource
    private OpuSysFilesService opuSysFilesService;


    @PostMapping("/uploadSingleFile.do")
    public JsonResult<String> uploadSingleFile(@RequestBody MultipartFile file){
       return opuSysFilesService.uploadSingleFile(file,MinioBucketEnum.EMAIL);
    }

    @GetMapping("/downFile.do/{md5Code}")
    public void downFile(@PathVariable("md5Code") String md5Code, HttpServletResponse response){
        opuSysFilesService.downFile(md5Code,MinioBucketEnum.EMAIL,response);
    }

    @GetMapping("/existFile.do/{md5Code}")
    public JsonResult<Boolean> judgeExistFile(@PathVariable("md5Code") String md5Code){
        Boolean existFile = opuSysFilesService.isExistFile(md5Code, MinioBucketEnum.EMAIL.getBucket());
        return JsonResult.success(existFile);
        
    }
}
